<template>
  <div class="postItem">
    <!-- 三图样式 -->
    <div class="threeImg" v-if="articlesData.images.length > 2">
      <!-- 添加跳转详情页 -->
      <div class="goDetail" @click="$router.push(`/post/detail?id=${articlesData.id}`)">
        <h4 class="post_title">{{ articlesData.title }}</h4>
        <p class="post_desc">{{ articlesData.summary }}</p>
        <div class="post_img">
          <img :src="articlesData.images[0]" alt />
          <img :src="articlesData.images[1]" alt />
          <img :src="articlesData.images[2]" alt />
        </div>
      </div>
      <!-- 底部模块 -->
      <div class="footer">
        <div class="info">
          <i class="el-icon-location-outline"></i>
          <span class="city">{{ articlesData.cityName }}</span>
          <span>by</span>
          <div class="user">
            <img
              :src="
                $axios.defaults.baseURL + articlesData.account.defaultAvatar
              "
              alt
            />
            <span class="account">{{ articlesData.account.nickname }}</span>
          </div>
          <i class="el-icon-view"></i>
          <span>{{ articlesData.watch }}</span>
        </div>
        <div class="like">
          <span>{{ articlesData.like }}</span> 赞
        </div>
      </div>
    </div>
    <!-- 单图 -->
    <div class="singleImg" v-else-if="articlesData.images.length < 3">
      <div class="post_cover" @click="$router.push(`/post/detail?id=${articlesData.id}`)">
        <img :src="articlesData.images[0]" alt />
      </div>
      <div class="post_desc">
        <div class="goDetail" @click="$router.push(`/post/detail?id=${articlesData.id}`)">
          <h4 class="post_title">{{ articlesData.title }}</h4>
          <p class="post_desc">{{ articlesData.summary }}</p>
          <!-- 底部模块 -->
        </div>
        <div class="footer">
          <div class="info">
            <i class="el-icon-location-outline"></i>
            <span class="city">{{ articlesData.cityName }}</span>
            <span>by</span>
            <div class="user">
              <img
                :src="
                  $axios.defaults.baseURL + articlesData.account.defaultAvatar
                "
                alt
              />
              <span class="account">{{ articlesData.account.nickname }}</span>
            </div>
            <i class="el-icon-view"></i>
            <span>{{ articlesData.watch }}</span>
          </div>
          <span class="like">
            <span>{{ articlesData.like }}</span> 赞
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    articlesData: {
      type: Object,
    },
  },
  data() {
    return {}
  },
  mounted() {
    // console.log('文章的数据', this.articlesData);
  },
}
</script>

<style lang="less" scoped>
.postItem {
  width: 100%;
  padding: 20px 0;
  border-bottom: 1px solid #eee;
  .goDetail {
    cursor: pointer;
  }
  h4 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 15px;
    font-weight: 400;
    font-size: 18px;
    &:hover {
      color: #ffa500;
    }
  }
  p {
    margin-bottom: 15px;
    line-height: 1.5;
    font-size: 14px;
    height: 63px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    color: #666;
  }
  .footer {
    width: 100%;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    i {
      margin: 0 5px;
    }
    .info {
      display: flex;
      align-items: center;
      color: #999;
      font-size: 13px;
      .city {
        margin: 0 5px;
      }
      .user {
        display: flex;
        align-items: center;
        color: #ffa500;
        margin: 0 5px;
        img {
          width: 16px;
          height: 16px;
          border-radius: 50%;
          margin: 0 5px;
          vertical-align: bottom;
        }
      }
    }
    .like {
      color: #ffa500;
    }
  }
  .threeImg {
    .post_img {
      margin: 15px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      img {
        width: 220px;
        height: 150px;
        display: block;
        -o-object-fit: cover;
        object-fit: cover;
      }
    }
  }
  .singleImg {
    display: flex;
    .post_cover {
      width: 220px;
      height: 150px;
      overflow: hidden;
      flex-shrink: 0;
      margin-right: 10px;
      img {
        width: 100%;
        height: 100%;
        -o-object-fit: cover;
        object-fit: cover;
      }
    }
    .post_desc {
      flex: 1;
    }
  }
}
</style>